package com.example;

import com.example.model.Product;
import com.example.model.Student;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Main {
    public static void main(String[] args) {
        // 加载Spring配置文件，初始化IOC容器
        ApplicationContext context = new ClassPathXmlApplicationContext("spring-config.xml");
        
        System.out.println("Spring IOC容器初始化完成！");
        
        // 从容器中获取Product对象
        Product product = (Product) context.getBean("product");
        System.out.println("\n从容器中获取的Product对象：");
        System.out.println(product);
        
        // 从容器中获取Student对象
        Student student = (Student) context.getBean("student");
        System.out.println("\n从容器中获取的Student对象：");
        System.out.println(student);
        
        // 演示通过不同方式获取bean
        Product product2 = context.getBean("product", Product.class);
        System.out.println("\n通过类型获取的Product对象：");
        System.out.println(product2);
        
        // 关闭容器
        ((ClassPathXmlApplicationContext) context).close();
    }
}
